# -*— coding: utf-8 -*-
# @Time: 2024/6/7 10:49
# @Author :Lin Zhou
# @Email : lin1013143@163.com
# @File : py_script.py
# @SoftWare: PyCharm
import datetime
import random
import time

from faker import Faker

faker = Faker()


def py_script(str_value):
    """
    参数化脚本，自定义数据
    :param str_value: 
    :return: 
    """
    if isinstance(str_value, str):
        if str_value.lower() == "py_time":
            return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        # 返回时间格式 示例：2024-06-18T17:11:15.099Z
        if str_value.lower() == "py_time_z":
            return datetime.datetime.now().isoformat(timespec='milliseconds') + 'Z'
        if str_value.lower() == "py_random":
            return random.randint(1, 3)
        if str_value.lower() == "faker_name":
            return faker.name()
        if str_value.lower() == "faker_address":
            return faker.address()
        if str_value.lower() == "faker_email":
            return faker.email()
        if str_value.lower() == "faker_phone":
            return faker.phone_number()
        if str_value.lower() == "faker_user":
            return faker.user_name()

    return str_value
